﻿<phone:PhoneApplicationPage
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" xmlns:eim="clr-namespace:Microsoft.Expression.Interactivity.Media;assembly=Microsoft.Expression.Interactions"
                            xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" xmlns:AllBots_Behaviour="clr-namespace:AllBots.Behaviour" x:Name="phoneApplicationPage" x:Class="AllBots.ChatPage"
                            xmlns:dp="clr-namespace:WP7DockPanel;assembly=WP7DockPanel"
                            SupportedOrientations="Portrait"
                            Orientation="Portrait"
                            mc:Ignorable="d"
                            d:DesignWidth="480"
                            d:DesignHeight="800"
                            shell:SystemTray.IsVisible="False"
                            >
	<!-- Navigation animations -->
    <toolkit:TransitionService.NavigationOutTransition>
        <StaticResource ResourceKey="OutTransitions" />
    </toolkit:TransitionService.NavigationOutTransition>
    <toolkit:TransitionService.NavigationInTransition>
        <StaticResource ResourceKey="InTransitions" />
    </toolkit:TransitionService.NavigationInTransition>
	
	<!--LayoutRoot contains the root grid where all other page content is placed-->
	<phone:PhoneApplicationPage.FontFamily>
		<StaticResource ResourceKey="PhoneFontFamilyNormal"/>
	</phone:PhoneApplicationPage.FontFamily>
	<phone:PhoneApplicationPage.FontSize>
		<StaticResource ResourceKey="PhoneFontSizeNormal"/>
	</phone:PhoneApplicationPage.FontSize>
	<phone:PhoneApplicationPage.Foreground>
		<StaticResource ResourceKey="PhoneForegroundBrush"/>
	</phone:PhoneApplicationPage.Foreground>
	<phone:PhoneApplicationPage.DataContext>
		<Binding Path="Chat" Source="{StaticResource Locator}"/>
	</phone:PhoneApplicationPage.DataContext>
	<!--LayoutRoot contains the root grid where all other page content is placed-->
	<Grid x:Name="LayoutRoot">
		<i:Interaction.Behaviors>
			<ec:DataStateBehavior Binding="{Binding IsSending}" TrueState="Sending" Value="True" FalseState="Writing"/>
		</i:Interaction.Behaviors>
		<VisualStateManager.VisualStateGroups>
			<VisualStateGroup x:Name="SendingStates">
				<VisualState x:Name="Sending">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Waitor">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
				<VisualState x:Name="Writing">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Waitor">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
			</VisualStateGroup>
		</VisualStateManager.VisualStateGroups>
		<Grid.Background>
			<ImageBrush Stretch="UniformToFill" ImageSource="/Background.jpg"/>
		</Grid.Background>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="*" />
		</Grid.RowDefinitions>

		<!--TitlePanel contains the name of the application and page title-->
		<StackPanel x:Name="TitlePanel"
		            Grid.Row="0"
		            Margin="24,24,0,12">
			<TextBlock x:Name="ApplicationTitle"
			           Text="{Binding AppResources.AppTitle, Source={StaticResource Localizator}}"
			           Style="{StaticResource PhoneTextNormalStyle}" Foreground="{StaticResource PhoneForegroundBrush}" />
			<TextBlock x:Name="PageTitle"
			           Text="{Binding Conversation.Bot.Name, StringFormat=\{0\}}"
			           Margin="-3,-8,0,0"
			           Style="{StaticResource PhoneTextTitle1Style}" FontSize="64" Foreground="{StaticResource HugeTitleBrush}" />
		</StackPanel>

		<!--ContentPanel - place additional content here-->
		<Grid x:Name="ContentGrid"
		      Grid.Row="1">
            <Grid.RowDefinitions>
            	<RowDefinition Height="0.285*" />
            	<RowDefinition Height="0.671*" />
            	<RowDefinition Height="0.044*"/>
            </Grid.RowDefinitions>
            <StackPanel>
                <TextBlock Text="{Binding AppResources.Message, Source={StaticResource Localizator}, StringFormat=\{0\} :}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="14,0,0,0" />
                <TextBox x:Name="textBox" Text="{Binding NextMessage.Content, Mode=TwoWay, UpdateSourceTrigger=Explicit}" >
                	<i:Interaction.Triggers>
                		<i:EventTrigger EventName="TextChanged">
                			<AllBots_Behaviour:UpdateBindingBehaviour/>
                		</i:EventTrigger>
                	</i:Interaction.Triggers>
                	<i:Interaction.Behaviors>
                	</i:Interaction.Behaviors>
                </TextBox>
                <Button Content="{Binding AppResources.Send, Source={StaticResource Localizator}}" Command="{Binding SendMessageCommand, Mode=OneWay}" />
            </StackPanel>
            <ListBox x:Name="ConversationLogListbox" ItemsSource="{Binding Conversation.Log}" Grid.Row="1" ItemTemplate="{StaticResource ChatMessageDataTemplate}" Margin="12,0,12,5" SelectedItem="{Binding SelectedMessage, Mode=TwoWay}" VerticalContentAlignment="Bottom" BorderThickness="2" BorderBrush="{StaticResource AccentBrush}">
            	<ListBox.Background>
            		<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
            			<GradientStop Offset="0" Color="#87000000"/>
            			<GradientStop Color="#FC000000" Offset="1"/>
            			<GradientStop Color="#44FFFFFF" Offset="0.442"/>
            			<GradientStop Color="#7DFFFFFF" Offset="0.534"/>
            			<GradientStop Color="#55000000" Offset="0.643"/>
            			<GradientStop Color="#39000000" Offset="0.349"/>
            			<GradientStop Color="#80FFFFFF" Offset="0.51"/>
            		</LinearGradientBrush>
            	</ListBox.Background>
            	<i:Interaction.Triggers>
            		<i:EventTrigger>
            			<AllBots_Behaviour:ScrollDownBehavior/>
            		</i:EventTrigger>
            	</i:Interaction.Triggers>
            </ListBox>
            <dp:DockPanel x:Name="Waitor" Grid.Row="2" Margin="4,0,0,0">
            	<TextBlock TextWrapping="Wrap" Text="{Binding Conversation.Bot.Name}" VerticalAlignment="Top" Margin="0,0,4,0" d:LayoutOverrides="Width" FontFamily="{StaticResource PhoneFontFamilySemiLight}" FontSize="{StaticResource PhoneFontSizeSmall}"/>
            	<TextBlock TextWrapping="Wrap" Text="{Binding AppResources.IsWriting, Source={StaticResource Localizator}}" VerticalAlignment="Top" FontFamily="{StaticResource PhoneFontFamilySemiLight}" FontSize="{StaticResource PhoneFontSizeSmall}"/>
            	<ProgressBar Height="10" VerticalAlignment="Center" IsIndeterminate="True" Foreground="{StaticResource SubtitleBrush}"/>
            </dp:DockPanel>
        </Grid>
	</Grid>

</phone:PhoneApplicationPage>